<template>
  <div class="app-container calendar-list-container">
    <!--押金订单列表 filter 条件查询 -->
    <div class="filter-container">
      <div style="display:inline-block;font-size:15px;">订单编号：</div>
      <el-input
        clearable
        @keyup.enter.native="handleFilter"
        v-model="listQuery.orderNo"
        style="width: 200px;margin-right:15px;margin-top:7px"
        class="filter-item"
        placeholder="请输入订单编号"
      />
      <div style="display:inline-block;font-size:15px;">支付流水号：</div>
      <el-input
        clearable
        @keyup.enter.native="handleFilter"
        v-model="listQuery.outTradeNo"
        style="width: 300px;margin-right:15px;margin-top:7px"
        class="filter-item"
        placeholder="请输入支付流水号"
      />
      <div style="display:inline-block;font-size:15px;">用户昵称：</div>
      <el-input
        clearable
        @keyup.enter.native="handleFilter"
        v-model="listQuery.nickName"
        style="width: 200px;margin-right:15px;margin-top:7px"
        class="filter-item"
        placeholder="请输入用户昵称"
      />
      <div style="display:inline-block;font-size:15px;">订单类型：</div>
      <el-select
        v-model="listQuery.status"
        placeholder="请选择订单类型"
        clearable
        class="filter-item"
        style="width: 200px;margin-right:15px;margin-top:7px"
      >
        <el-option label="缴纳押金" value="1"></el-option>
        <el-option label="退押金" value="2"></el-option>
      </el-select>
      <el-button
        class="filter-item"
        type="primary"
        v-waves
        icon="el-icon-search"
        @click="handleFilter"
      >查找</el-button>
      <el-button
        type="primary"
        class="filter-item"
        @click="handleDownload"
        icon="el-icon-download"
        :loading="downloadLoading"
      >导出</el-button>
    </div>
    <!-- table 表格 -->
    <el-table
      :data="list"
      v-loading="loading.list"
      element-loading-text="给我一点时间"
      border
      fit
      highlight-current-row
      style="width: 100%"
    >
      <el-table-column label="序号" prop="index" align="center" width="80px"/>
      <el-table-column label="订单编号" prop="orderNo" align="center"/>
      <el-table-column label="支付流水号" prop="outTradeNo" align="center" width="300px"/>
      <el-table-column label="用户昵称" prop="nickName" align="center"/>
      <el-table-column label="联系方式" prop="userPhone" align="center"/>
      <el-table-column label="交易金额" prop="amount" align="center"/>
      <el-table-column label="订单状态" prop="statusLabel" align="center"/>
      <el-table-column label="支付类型" prop="payTypeLabel" align="center"/>
      <el-table-column label="创建时间" prop="cTime" align="center"/>
    </el-table>
    <!-- pagination 分页 -->
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="listQuery.offset"
        :page-sizes="[10, 20, 30, 40, 100, 400]"
        :page-size="listQuery.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { queryOrderDeposit } from "@/api/equipmentOrders";
import { parseTime, getdTime } from "@/utils";
export default {
  name: "equipmentOrders_list",
  data() {
    return {
      total: 0,
      listQuery: {
        offset: 1,
        limit: 10,
        nickName: "",
        status: "",
        payType: "",
        orderNo: "",
        outTradeNo: ""
      },
      list: null,
      loading: {
        list: false,
        download: false
      },
      downloadLoading: false
    };
  },
  methods: {
    //导出
    handleDownload() {
      this.downloadLoading = true;
      import("@/vendor/Export2Excel").then(excel => {
        const tHeader = [
          "订单编号",
          "支付流水号",
          "用户昵称",
          "联系方式",
          "交易金额",
          "订单类型",
          "支付类型",
          "创建时间"
        ];
        const filterVal = [
          "orderNo",
          "outTradeNo",
          "nickName",
          "userPhone",
          "amount",
          "statusLabel",
          "payTypeLabel",
          "cTime"
        ];
        const data = this.formatJson(filterVal, this.list);
        excel.export_json_to_excel({
          header: tHeader,
          data,
          filename: "押金订单列表"
        });
        this.downloadLoading = false;
      });
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v =>
        filterVal.map(j => {
          return v[j];
        })
      );
    },

    //获取押金订单列表
    async queryOrderDeposit() {
      this.loading.list = true;
      try {
        const { data } = await queryOrderDeposit({ ...this.listQuery });
        this.list = data.records.map((item, index) => {
          return {
            index: index + 1,
            ...item,
            statusLabel: item.status == 1 ? "缴纳押金" : "退押金",
            payTypeLabel: item.payType == 1 ? "微信" : "支付宝"
          };
        });
        this.total = data.total;
      } catch (error) {}
      this.loading.list = false;
    },
    handleFilter() {
      this.listQuery.offset = 1;
      this.queryOrderDeposit();
    },
    handleSizeChange(val) {
      this.listQuery.limit = val;
      this.queryOrderDeposit();
    },
    handleCurrentChange(val) {
      this.listQuery.offset = val;
      this.queryOrderDeposit();
    },
    formatDate(date, offset) {
      if (date && typeof date == "object") {
        const d = date[offset];
        return new Date(d).getTime();
      }
      return "";
    }
  },
  created() {
    this.queryOrderDeposit();
  }
};
</script>
